package com.ruoyi.web.controller.work;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.work.domain.WorkFill;
import com.ruoyi.work.domain.vo.MyFillRecord;
import com.ruoyi.work.domain.vo.MyProjectRecord;
import com.ruoyi.work.service.IWorkRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: MMDZ
 * @Desc: TODO 填报记录
 */
@RestController
@RequestMapping("/work/record")
public class WorkRecordController extends BaseController {

    @Autowired
    private IWorkRecordService workRecordService;

    /**
     * 查询自己的填报记录（默认7天）
     *
     * @param record
     * @return
     */
    @PreAuthorize("@ss.hasPermi('work:record:list')")
    @GetMapping("/myfill")
    public AjaxResult record(MyFillRecord record) {
        List<MyFillRecord> list = workRecordService.selectRecordList(record);
        return AjaxResult.success(list);
    }

    /**
     * 查询自己参加的项目
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('work:record:list')")
    @GetMapping("/mypro")
    public AjaxResult myProject() {
        Long userId = getUserId();
        List<MyProjectRecord> list = workRecordService.selectMyProjectList(userId);
        return AjaxResult.success(list);
    }

    /**
     * 查询自己的当天申报详情
     *
     * @param record
     * @return
     */
    @PreAuthorize("@ss.hasPermi('work:record:view')")
    @PostMapping("/view")
    public AjaxResult view(@RequestBody MyFillRecord record) {
        if (StringUtils.isEmpty(record.getFillDate()))
            throw new ServiceException("获取填报日期信息异常，请联系管理员", HttpStatus.ERROR);
        List<WorkFill> list = workRecordService.selectRecordByDataAndUserId(record);
        return AjaxResult.success(list);
    }
}
